package com.xlisteven.springbootjpathymeleafcurd.service.impl;


import com.xlisteven.springbootjpathymeleafcurd.mapper.UserMapper;
import com.xlisteven.springbootjpathymeleafcurd.pojo.User;
import com.xlisteven.springbootjpathymeleafcurd.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> getUserList() {
        return userMapper.findAll();
    }

    public Optional<User> findUserById(long id) {
        return userMapper.findById(id);
    }

    @Override
    public void save(User user) {
        userMapper.save(user);
    }

    @Override
    public Optional<User> findUserById(Long id) {
        return userMapper.findById(id);
    }

    @Override
    public void edit(User user) {
       userMapper.save(user);
    }

    @Override
    public void delete(Long id) {
        User user = new User();
        user.setuId(id);
        userMapper.delete(user);
    }

}


